<?php

define('IN_ELCIUS', true);
define('IN_PHPBB', true);

define('ELCIUS_DEBUGGING',true);  // TODO: propper debugger/error handler

// common functions, not specific to this application
require_once("./dependencies/functions.misc.php"); // clean()

// php settings
date_default_timezone_set("Pacific/Auckland");
header('Content-Type: text/html; charset=UTF-8');

// application settings (admin defined)
require_once("./data/settings.application.php"); // list of enabled content and widgets

// functions specific to this application
require_once("./dependencies/functions.common.php"); // content file handling stuff

// content database managment class
require_once("./dependencies/class.KiwiDB.php"); // media, uploads, extra
KiwiDB::Initialize();

// content database managment class
require_once("./dependencies/class.ExternalContent.php"); // class for fetching remote data (from battle.net, wol, etc)
ExternalContent::Initialize();

// authentication class
require_once("./dependencies/class.KiwiAuth.php");
KiwiAuth::Initialize();

// PHPBB Authentication

$phpbb_root_path = './forums/';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
require($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
$auth->acl($user->data);
$user->setup();

KiwiAuth::NewPHPBBSession( $user, $auth ); // collects phpbb's authentication results

// TODO: PHPBB leaves a bunch of stuff laying around

// Wow Armory API
require_once('./dependencies/class.WowArmory.php'); //include the main class 
WowArmory::Initialize();

//WowArmory::Fetch('character','elcius','frostmourne','stats,talents,items,reputation,titles,professions,appearance,companions,mounts,achievements,progression,pvp,quests,pets,guild');
//WowArmory::Fetch('guild','Kill it Please','frostmourne','');

// handle user request
require_once("./dependencies/class.KiwiRequest.php");
KiwiRequest::Initialize(); 
KiwiRequest::Process(); // checks if request is valid, 404, home, has access, checks skin settings, etc.

// collect page data
$PageData = array(
	'Title' => ucfirst( KiwiRequest::$Data['ContentName'] ), // title of the content
	'Dependencies' => '', // TODO: should this even be defined here?, or should the skin backend handle it.
	'Content' => KiwiRequest::GetContentTemplate(), // get the html file for the content
	'User' => KiwiAuth::GetPublicUserData(), // data that is ok to print
	'DateTime' => date( $Settings['TimeFormat'] ),
);



KiwiRequest::IncludeWidgets(); // data collection for sidebars and other global systems, guild data is a widget
KiwiRequest::IncludeContent(); // backend for specific pages, uploading, managment, etc
KiwiRequest::IncludeSkinBackend(); // skin scripting, user preferences etc.

$out = 'Ajax';
if( is_null( GetRequestVar('Ajax') ) ){
	// Generate Page HTML
	$out = ProcessTemplate( KiwiRequest::GetPageTemplate(), $PageData );
}

// finish up and print
KiwiDB::Close();

echo $out;

?>